﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace TV
{
    public abstract class CBroadcastNoTouchDeployment
    {

        protected String m_arguments = null;
        protected String m_appLaunchUrl = null;
        protected String m_trimmedUrl = null;


        public String Arguments
        {
            get
            {
                if (null == m_arguments)
                {
                    return null;
                }
                return m_arguments;
            }
        }

        public String OriginalUrl
        {
            get
            {
                return m_appLaunchUrl;
            }
        }

        public String TrimmedUrl
        {
            get
            {
                return m_trimmedUrl;
            }
        }


        public CBroadcastNoTouchDeployment()
        {
            AppDomain domain = AppDomain.CurrentDomain;
            Object ntdUrl = domain.GetData("APP_LAUNCH_URL");
            m_appLaunchUrl = (ntdUrl != null ? ntdUrl.ToString() : String.Empty);

            if (String.IsNullOrEmpty(m_appLaunchUrl))
            {
                return;
            }

            Int32 startOfArgsIndex = m_appLaunchUrl.IndexOf('?');

            if (startOfArgsIndex > 0)
            {

                m_trimmedUrl = m_appLaunchUrl.Substring(0, startOfArgsIndex);

                //domain.SetData("APP_LAUNCH_URL", trimmedUrl);
                //AppDomain.CurrentDomain.SetData("APP_LAUNCH_URL", m_trimmedUrl);
                //AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", m_trimmedUrl + ".config");
                domain.SetData("APP_LAUNCH_URL", m_trimmedUrl);
                domain.SetData("APP_CONFIG_FILE", m_trimmedUrl + ".config");

                String queryString = m_appLaunchUrl.Substring(startOfArgsIndex + 1);
                parseUrlQueryString(queryString);

            }

        }

        protected abstract void parseUrlQueryString(String args);

    }
}
